﻿package net.wangit.app.user;


import net.wangit.LabelUtil;
import net.wangit.Unit;
import net.wangit.app.AppResource;
import net.wangit.context.ActionContext;
import net.wangit.support.UnitInterceptor;
import net.wangit.user.Guest;

public class AccessFailedUI implements UnitInterceptor {
  public String intercept(ActionContext ac, Unit unit) throws Exception {
    String message;
    if (ac.getVisitor().getUser() instanceof Guest) {
      message = LabelUtil.get(ac, AppResource.FILE,
          AppResource.ACCESS_FAILED_WITHOUT_LOGIN);
    } else {
      message = LabelUtil.get(ac, AppResource.FILE, AppResource.ACCESS_FAILED);
      unit.removeElement("login");
    }
    unit.getElement("message").setCustom(message);
    return unit.write(ac);
  }

}
